From 00cb4c66cfb48b4dee5568be6ac6d60505ef88cf Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 30 Mar 2023 07:43:12 +0200 Subject: [PATCH] testdatatable: Add a --pages option That way, local scrolling is available and the scrolling isn't random. Recycling should now involve reordering the recycled widgets instead of just keeping their order because all of them got recycled. --- tests/testdatatable.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/testdatatable.c b/tests/testdatatable.c index 72de5829e4..6e3ca992d2 100644 --- a/tests/testdatatable.c +++ b/tests/testdatatable.c @@ -5,6 +5,11 @@ #include "frame-stats.h" +static gboolean no_auto_scroll = FALSE; +static gint n_columns = 20; +static double scroll_pages = 0; + + /* This is our dummy item for the model. */ #define DATA_TABLE_TYPE_ITEM (data_table_item_get_type ()) G_DECLARE_FINAL_TYPE (DataTableItem, data_table_item, DATA_TABLE, ITEM, GObject) @@ -48,6 +53,18 @@ set_adjustment_to_fraction (GtkAdjustment *adjustment, fraction * (upper - page_size)); } +static void +move_adjustment_by_pages (GtkAdjustment *adjustment, + double n_pages) +{ + double page_size = gtk_adjustment_get_page_size (adjustment); + double value = gtk_adjustment_get_value (adjustment); + + value += page_size * n_pages; + /* the adjustment will clamp properly */ + gtk_adjustment_set_value (adjustment, value); +} + static gboolean scroll_column_view (GtkWidget *column_view, GdkFrameClock *frame_clock, @@ -57,7 +74,10 @@ scroll_column_view (GtkWidget *column_view, vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (column_view)); - set_adjustment_to_fraction (vadjustment, g_random_double ()); + if (scroll_pages == 0.0) + set_adjustment_to_fraction (vadjustment, g_random_double ()); + else + move_adjustment_by_pages (vadjustment, (g_random_double () * 2 - 1) * scroll_pages); return TRUE; } @@ -172,9 +192,6 @@ parse_widget_arg (const gchar* option_name, } } -static gboolean no_auto_scroll = FALSE; -static gint n_columns = 20; - static GOptionEntry options[] = { { "widget", @@ -203,6 +220,15 @@ static GOptionEntry options[] = { "Column count", "COUNT" }, + { + "pages", + 'p', + G_OPTION_FLAG_NONE, + G_OPTION_ARG_DOUBLE, + &scroll_pages, + "Maximum number of pages to scroll (or 0 for random)", + "COUNT" + }, { NULL } }; -- 2.30.2